# 默写一个装饰器，用来输出函数的执行时间
import time
def foo(a, b):
    count = 1
    while True:
        if count > (a + b) ** 2:
            break
        count += 1

def clock_it(func, a, b):
    start_time = time.time()
    result = func(a, b)
    end_time = time.time()
    print(f"{func.__name__} execute time: {format(end_time - start_time, '.2f')} s")
    return result

result = clock_it(foo, 99, 124)
print(result)


# 使用装饰器来为斐波那契函数添加缓存
def cache_deco(func):
    def wrapper(n, *args, **kwargs):
        result = func(n, *args, **kwargs)
        return result
    return wrapper


@cache_deco
def fibo(n):
    if n == 0:
        return n
    elif n == 1:
        return n
    else:
        return fibo(n - 2) + fibo(n - 1)
print(fibo(12))





